import React, {useState} from "react";
import {Container} from "./style";
import {connect} from "react-redux";
import {withRouter} from "react-router-dom";
import Config from "@/config";
import {RandomStr} from "@/util/global";
import {SwapOutlined} from '@ant-design/icons';
import {Divider, Menu} from "antd";

const MineBar = (props) => {
    const [current, setCurrent] = useState();
    function handleClick(number) {
        switch (number) {
            case 1:
                props.router.push('/mine/info');
                break;
            case 2:
                props.router.push('/mine/my-vip');
                break;
            case 3:
                props.router.push('/mine/info');
                break;
            case 4:
                props.router.push('/mine/info');
                break;
            case 999:
                props.router.push('/mine/admin/data-control');
                break;
            case 1000:
                props.router.push('/mine/admin/data-control/u-list');
                break;
            case 1001:
                props.router.push('/mine/admin/home-control');
                break;
            case 1002:
                props.router.push("/mine/admin/game-control");
                break;
            case 1003:
                props.router.push("/mine/admin/other-control/menu");
                break;
            case 1004:
                props.router.push("/mine/admin/home-banner");
                break;
            default:
                props.router.push('/mine/info');
                break;
        }
    }

    return (
        <Container>
            {/*<Menu onClick={onClick} selectedKeys={[current]} mode="horizontal" items={items} />*/}
            <ul>
                <>
                    <Divider orientation={"left"}
                             style={{margin: '0px 0', padding: '0 10px 0 0px', borderColor: "none"}}>
                        <label>用户中心</label>
                    </Divider>
                    <li onClick={() => handleClick(1)} key={"/mine/info"}
                        className={`${props.location.pathname === "/mine/info" ? "select" : null}`}>
                        <Config.IconFont type={'icon-yonghuziliaogerenxinxigerenziliao-xianxing'}
                                         style={{fontSize: '13px'}}/>
                        信息资料
                    </li>
                    <li onClick={() => handleClick(2)} key={RandomStr()}>
                        <Config.IconFont type={'icon-renzhengyonghu'} style={{fontSize: '13px'}}/>
                        我的会员
                    </li>
                    <li onClick={() => handleClick(3)} key={RandomStr()}>
                        <Config.IconFont type={'icon-shezhi'} style={{fontSize: '13px'}}/>
                        偏好设置
                    </li>
                    <li onClick={() => handleClick(4)} key={RandomStr()}>
                        <Config.IconFont type={'icon-shoucang1'} style={{fontSize: '13px'}}/>
                        我的收藏
                    </li>
                </>
                {
                    props.user.isAdmin === '1' ?
                        <>
                            <Divider orientation={"left"}
                                     style={{margin: '0px 0', padding: '0 10px 0 0px', borderColor: "none"}}>
                                <label>控制台</label>
                            </Divider>
                            <li onClick={() => handleClick(1000)} key={"/mine/admin/data-control/u-list"}
                                className={`${props.location.pathname.startsWith("/mine/admin/data-control/u-list") ? "select" : null}`}
                            >
                                <Config.IconFont type={'icon-shujuwajue'} style={{fontSize: '13px'}}/>
                                数据管理
                            </li>
                            <li onClick={() => handleClick(1001)} key={'/mine/admin/home-control'}
                                className={`${props.location.pathname.startsWith("/mine/admin/home-control") ? "select" : null}`}
                            >
                                <Config.IconFont type={'icon-shouye'} style={{fontSize: '13px'}}/>
                                首页管理
                            </li>
                            <li onClick={() => handleClick(1004)} key={'/mine/admin/home-banner'}
                                className={`${props.location.pathname.startsWith("/mine/admin/home-banner") ? "select" : null}`}
                            >
                                <SwapOutlined />
                                轮播图管理
                            </li>
                            <li onClick={() => handleClick(1002)} key={"/mine/admin/game-control"}
                                className={`${props.location.pathname.startsWith("/mine/admin/game-control") ? "select" : null}`}
                            >
                                <Config.IconFont type={'icon-youxi1'} style={{fontSize: '13px'}}/>
                                游戏管理
                            </li>
                            <li onClick={() => handleClick(1003)} key={"/mine/admin/other-control/menu"}
                                className={`${props.location.pathname.startsWith("/mine/admin/other-control/menu") ? "select" : null}`}>
                                <Config.IconFont type={'icon-qita'} style={{fontSize: '13px'}}/>
                                其他管理
                            </li>
                        </>
                        :
                        null
                }
            </ul>
        </Container>
    )
}
const mapStateToProps = (state) => {
    return {
        user: state.getIn(['user']).toJS()
    }
}
const mapDispatchToProps = (dispatch) => {
    return {}
}
export default connect(mapStateToProps, mapDispatchToProps)(withRouter(MineBar));
